﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Vikipedia.CommonTools.HashCompute;

namespace Vikipedia.VikiPlayer.SL
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
   
        }

        void Movie_CurrentStateChanged(object sender, RoutedEventArgs e)
        {
            switch (Movie.CurrentState)
            { 
                case MediaElementState.Playing :
                    Sld1.Maximum = Movie.NaturalDuration.TimeSpan.TotalSeconds;
                    break;

            }
        }



        private void UserControl_DragEnter(object sender, DragEventArgs e)
        {
            e.Handled = true;

        }

        private void UserControl_Drop(object sender, DragEventArgs e)
        {
            var x = e.Data.GetData(System.Windows.DataFormats.FileDrop) as System.IO.FileInfo [];
           
           
           
            


         
            if (x != null)
            {
                var ms = x[0].OpenRead();
                Movie.SetSource(ms);
                Movie.Play();
                System.Threading.ThreadPool.QueueUserWorkItem(
                                (o) =>
                                {
                                    var s = Hash.DoFileHash(x[0]).ToED2k("");
                                  Dispatcher.BeginInvoke (()=>  MessageBox.Show(s));
                                }
                                );


                



            }
        }


        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {

            double sec = e.NewValue;

            var ts = new TimeSpan(0, 0, (int)sec);

            Movie.Position = ts;
        }

      
    }
}
